package com.hzqy.web.ac.epg;

import java.text.SimpleDateFormat;
import java.util.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.plaf.metal.MetalIconFactory.FolderIcon16;

import com.hzqy.commons.service.AuthenticatedService;
import com.hzqy.web.vo.AcWinningVo;
import com.hzqy.web.vo.CmContentVo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.RedisUtils;
import com.hzqy.commons.utils.SystemConfigUtils;
import com.hzqy.service.epg.AcIntegralService;
import com.hzqy.service.epg.AcIptvListServiceBean;
import com.hzqy.service.epg.RedisService;
import com.hzqy.service.epg.epgCommonService;
import com.hzqy.web.login.SessionKey;


import com.hzqy.web.vo.activity.ActivityVoteUserVo;
import com.hzqy.web.vo.epg.AcIntegralVo;
import com.hzqy.web.vo.epg.CmSvcVoteTotalVo;
import com.hzqy.web.vo.epg.gcw.AcStbUserVotenum;
/**
 * 边锋双扣活动积分接口
 
 * @author sujz
 *
 */
@Controller
@RequestMapping("/integralBF")
public class AcIntegralAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private AcIntegralService acIntegralService;
	@Resource
	private AcIntegralService clearVoteCacheService;
	@Resource
	private epgCommonService  epgComService;
	@Resource
	private AcIptvListServiceBean iptvServiceBean;

	/**
	 * 社区总排名
	 * 	传入本次活动id --aiv_activity
	 *   
	 *  @return
	 *  	    aiv_integralNum:当前社区总票数
	 *  		aiv_rownum:当前排名
	 *  		aiv_sasName:社区名称
	 *  		aiv_sasDesc:社区描述
	 *  		aiv_sasId: 社区id
	 *  		aiv_likeNum:点赞数
	 */
	@RequestMapping("/selectIntegralBF")
	@ResponseBody
	public  Object selectCommunityIntegral(AcIntegralVo aiv,int pageNo,int pageSize,HttpServletRequest request){
		HttpSession session = request.getSession();
		String userID = String.valueOf(session.getAttribute(SessionKey.SESSION_SERVERID));
		aiv.setAiv_serviceId(userID);
		Map<String,Object> map = acIntegralService.selectCommunityIntegral(aiv,pageNo,pageSize);
		return map;
	}
	
	//社区总条数
	@RequestMapping("/selectCommunityCount")
	@ResponseBody
	public Object selectCommunityCount(AcIntegralVo aiv) {
		Map<String,Object> map = acIntegralService.selectCommunityCount(aiv);
		return map;
	}
	
	/**
	 * 社区点赞数
	 * @param aiv_sasId 社区id  aiv_sasName  社区名称
	 * @param aiv_activity  投票的活动id
	 * @param request
	 * @return
	 */
	@RequestMapping("/selectCommunityLike")
	@ResponseBody
	public  Object selectCommunityLike(String aiv_sasId, String aiv_activity,String aiv_sasName,HttpServletRequest request){
		HttpSession session = request.getSession();
		AcIntegralVo map = acIntegralService.selectCommunityLike(aiv_sasId,aiv_activity,aiv_sasName);
		return map;
	}

	/**
	 * 社区积分排名前五的
	 *    参数  ：aiv_sasId   社区id
	 *   	 aiv_type   当前时间所属期数
	 * @return
	 * 		aiv_integralNum     用户积分
	 * 		aiv_phone   用户手机
	 * 		aiv_sasId 社区id
	 * 		aiv_type;//活动期数
	 * 		aiv_sasName;//社区名称
	 * 		aiv_sasDesc;//街道描述 f_sas_desc
	 */
	@RequestMapping("/selectAivPhone")
	@ResponseBody
	public   Object  selectAivPhone(AcIntegralVo aiv){
		List<AcIntegralVo> list = acIntegralService.selectAivPhone(aiv);
		return list;
	}

	/** 积分前十用户排名
	  * 参数  ：aiv_type   当前时间所属期数   aiv_serviceId itv账号 用于查询我的排名
	 * @return    allrank  前十   myrank  我的
	 * 		aiv_integralNum     用户积分
	 * 		aiv_rownum     排名
	 * 		aiv_phone   用户手机
	 * 		aiv_sasId  社区id
	 * 		aiv_serviceid  itv账号
	 * 		aiv_type;//活动期数
	 * 		aiv_sasName;//社区名称
	 * 		aiv_sasDesc;//街道描述 f_sas_desc
	 */
	@RequestMapping("/selectIndividualRanking")
	@ResponseBody
	public  Object selectIndividualRanking(AcIntegralVo aiv,HttpServletRequest request){
		HttpSession session = request.getSession();
		String userID = String.valueOf(session.getAttribute(SessionKey.SESSION_SERVERID));
		aiv.setAiv_serviceId(userID);
		Map<String,Object> map = acIntegralService.selectIndividualRanking(aiv);
		return map;
	}
	//查询社区id
	@RequestMapping("/selectSasId")
	@ResponseBody
	public Object selectSasId(HttpServletRequest request) {
		HttpSession session = request.getSession();
		String userID = String.valueOf(session.getAttribute(SessionKey.SESSION_SERVERID));
		return acIntegralService.selectSasId(userID);
	}
	
	/**
	 * 
	 * @param acvote  活动id， 票数， 目标id
	 * @param request
	 * @return
	 */
	@RequestMapping("/insertACLikeVote")
	@ResponseBody
	public  Object insertACLikeVote(ActivityVoteUserVo acvote,String serverRandom,HttpServletRequest request){
		Map<String,Object> map = new HashMap<String,Object>();
		HttpSession session = request.getSession();
		String userID = String.valueOf(session.getAttribute(SessionKey.SESSION_SERVERID));
		String random=String.valueOf(session.getAttribute(userID+"random"));
		if (!random.equals(serverRandom)) {
			map.put("error", "RandomError");
			return map;
		}
		acvote.setF_avu_serverid(userID);
		int contend = acvote.getF_avu_contentid();
		acvote.setF_avu_contentid(0);
		Map<String,Object> map2 = acIntegralService.selectAcLikeVotenum(acvote);
		if (acvote.getF_avu_votenum() > (int)map2.get("surplus") ) {
			map.put("resulet", -1);
		}else {
			acvote.setF_avu_type(2);
			acvote.setF_avu_source(0);
			acvote.setF_avu_memo("用户投票");
			acvote.setF_avu_obligate1(0);
			acvote.setF_avu_obligate2("0");
			acvote.setF_avu_contentid(contend);
			int ins = acIntegralService.insertACLikeVote(acvote);
			map.put("resulet", ins);
		}
		
		return map;
	}
	/**
	 * 投票接口   此接口可以增加投票总表
	 * @param f_avu_activityid 活动id
	 * @param f_avu_votenum  票数
	 * @param f_avu_contentid 目标id
	 * @param f_avu_insertType 投票类型 1：不进行总票数插入操作  05.23日已不使用此参数， 更改后投票都会计入总票总数表
	 * @return resulet： 流水表插入结果    0:投票失败
	 */
	@RequestMapping("/insertACLikeVoteV2")
	@ResponseBody
	public  Object insertACLikeVoteV2(ActivityVoteUserVo acvote,HttpServletRequest request){
		Map<String,Object> map = new HashMap<String,Object>();
		HttpSession session = request.getSession();
		String userID = String.valueOf(session.getAttribute(SessionKey.SESSION_SERVERID));
		acvote.setF_avu_serverid(userID);
		acvote.setF_avu_type(2);
		acvote.setF_avu_source(0);
		acvote.setF_avu_memo("用户投票");
		acvote.setF_avu_obligate1(0);
		acvote.setF_avu_obligate2("0");
		map = acIntegralService.insertACLikeVoteV2(acvote);
		return map;
	}
	/**
	 * 查询已投票数
	 * @param f_avu_activityid 活动id
	 * @param f_avu_serverid  投票人
	 * @param f_avu_contentid 目标id
	 * @param f_avu_startTime 投票开始时间
	 * @param f_avu_endTime   投票结束时间
	 * @return used：已投票数
	 */
	@RequestMapping(value="/selectAcLikeVotenum")
	@ResponseBody
	public Object selectAcLikeVotenum(ActivityVoteUserVo acvote,HttpSession session) {
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		acvote.setF_avu_serverid(userid);
		Map<String,Object> map = new HashMap<String,Object>();
		map = acIntegralService.selectAcLikeVotenum(acvote);
		return map;
	}
	/**
	 * 查询投票列表
	 * @param f_avu_activityid 活动id
	 * @param f_avu_serverid  投票人
	 * @param f_avu_contentid 目标id
	 * @param f_avu_startTime 投票开始时间
	 * @param f_avu_endTime   投票结束时间
	 * @return ActivityVoteUserVo：投票流水记录   f_cc_searchname：选手编号
	 */
	@RequestMapping(value="/selectAcLikeVoteList")
	@ResponseBody
	public Object selectAcLikeVoteList(ActivityVoteUserVo acvote,HttpSession session) {
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		acvote.setF_avu_serverid(userid);
		List<ActivityVoteUserVo> VoteList = acIntegralService.selectAcLikeVoteList(acvote);
		return VoteList;
	}
	/**
	 * 根据分类查询选手及其获取的总票数，数量
	 * @param f_catalog_id 分类id
	 * @param f_catalog_ids  分类id组
	 * @param f_cp_cprid 图片类型
	 * @param luckyBaby_qualification=xybb 幸运宝贝资格查询
	 * @param f_cc_searchname   编号
	 * @param f_csvt_activityid   活动id
	 * @return 数量
	 */
	@RequestMapping("/selectAcContentVotenumCount")
	@ResponseBody
	public Object selectAcContentVotenumCount(HttpSession session,int f_catalog_id,String f_cp_cprid,CmContentVo contentVo) {
		int count= acIntegralService.selectAcContentVotenumCount(f_catalog_id,f_cp_cprid,contentVo);
		Map<String, Integer> map=new HashMap<String, Integer>();
		map.put("count", count);
		return map;
	}
	/**
	 * 根据分类查询选手及其获取的总票数
	 * @param f_catalog_id 分类id
	 * @param f_catalog_ids  分类id组
	 * @param f_cp_cprid 图片类型
	 * @param luckyBaby_qualification=xybb 幸运宝贝资格查询
	 * @param f_cc_searchname   编号
	 * @param f_csvt_activityid   活动id
	 * @return CmContentVo：选手信息   f_csvt_votecount：选手总票数  surplus_time:投票剩余时间 f_catalog_isOpen:1开放
	 */
	@RequestMapping(value="/selectAcContentVotenumList")
	@ResponseBody
	public Object selectAcContentVotenumList(HttpSession session, int f_catalog_id, int pageNo, int pageSize, String f_cp_cprid, CmContentVo contentVo) {
		List<CmContentVo> contentList = acIntegralService.selectAcContentVotenumList(f_catalog_id, pageNo, pageSize,f_cp_cprid,contentVo);
		return contentList;
	}
	/**
	 * 清楚投票的缓存信息
	 * */
	@RequestMapping("/clear_voteCache")
	@ResponseBody
	public Object clearVoteCache(){
		List<ActivityVoteUserVo> result = clearVoteCacheService.clearVoteCache();
		return "结果：<br/>清空投票缓存"+result;
	}
	/**
	 * 领票成功后入库可投票数表  ac_stb_user_votenum
	 * @param f_asuv_activityid 活动id
	 * @param f_asuv_votenum  票数
	 * @param f_asuv_serverid 目标id
	 * @param f_asuv_source 投票来源 1有料签到，2产品开通，3赠票卡',  
	 * @param f_asuv_memo 备注
	 * @param f_asuv_resolution 1标清  2高清   0未知   已从session中获取
	 * @return result： 可投票数表插入结果   
	 */
	@RequestMapping("/insertAcStbUserVotenum")
	@ResponseBody
	public  Object insertAcStbUserVotenum(AcStbUserVotenum acvote,HttpServletRequest request){
		Map<String,Object> map = new HashMap<String,Object>();
		HttpSession session = request.getSession();
		String userID = String.valueOf(session.getAttribute(SessionKey.SESSION_SERVERID));
		String resolution=String.valueOf(session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION));
		int rsl=0;
		if(!"".equals(resolution)&&!"null".equals(resolution)&& null!=resolution){
			rsl=Integer.parseInt(resolution);
		}
		acvote.setF_asuv_resolution(rsl);
		acvote.setF_asuv_serverid(userID);
		acvote.setF_asuv_memo("领票入库");
		acvote.setF_asuv_obligate1(0);
		int ins = acIntegralService.insertAcStbUserVotenum(acvote);
		map.put("result", ins);
		return map;
	}
	/**
	 * 查询广场舞活动用户可投票数
	 * @param f_asuv_activityid 活动id
	 * @param f_asuv_source  投票来源 1有料签到，2产品开通，3赠票卡',
	 * @param f_asuv_serverid 目标id
	 * @param f_asuv_resolution 高标清  1标清  2高清     0未知   已从session中获取
	 * @param f_asuv_startTime 票数有效时间   当天有效  此接口内部已完成 开始与结束时间提取，不用再传此参数
	 * @param f_asuv_endTime   票数有效结束时间
	 * @return all_count：用户可投票数  day_count:每日基础票数  order_count:订购获得票数  ylqd_count:有料签到获得票数  cpkt_count:产品开通获得票数  zpk_count:赠票卡获得票数
	 */
	@RequestMapping(value="/selectGCWEffectiveVoteCount")
	@ResponseBody
	public Object selectGCWEffectiveVoteCount(AcStbUserVotenum acvote,HttpServletRequest request,HttpServletResponse response) {
		Map<String,Object> returnMap =new HashMap<>();
		returnMap = acIntegralService.selectGCWEffectiveVoteCount(acvote,request,response);
		return returnMap;
	}
	/**
	 * @Description: 是否赠票
	 * @Param:  * @param null
	 * @return:  增票结果result：1.失败 0,成功 2，错误
	 * @Author: LiuL
	 * @Date: 2019/5/15
	 */
	@RequestMapping("/selectAcTicketnum")
	@ResponseBody
	public Object selectAcTicketNum(HttpSession session, String f_at_password,String activityid){
		Map<String,String> map=new HashMap<String,String>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		String resolution =(String) session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION);//1.标清 2.高清
		map = acIntegralService.addVoteNum(f_at_password,userid,resolution,activityid);
		return map;
	}
	/**
	 * @Description: 查询验证码（品质标）
	 * @Param:  * @param null activityid--》代替f_at_openid 字段  f_at_frequency 为2 代表品质标机顶盒兑换
	 * @return:  增票结果result：1.失败 0,成功 2，错误
	 * @Author: LiuL
	 * @Date: 2019/9/15
	 */
	@RequestMapping("/selectPzbCodeNum")
	@ResponseBody
	public Object selectAcTicketPzbNum(HttpSession session,String activityid){
		Map<String,String> map=new HashMap<String,String>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		String resolution =(String) session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION);//1.标清 2.高清
		map = acIntegralService.selectPzbCodeNum(userid,resolution,activityid);
		return map;
	}
	/**
	 * 插入用户票数流水记录表
	 * @param session
	 * @param f_asuv_serverid,用户id;f_asuv_activityid:活动编号；
	 *        f_asuv_votenum：票数；f_asuv_source：票数来源；f_asuv_memo：备注，建议携带
	 * @return
	 */
	@RequestMapping("/insertUserVotenum")
	@ResponseBody
	public Object insertUserVotenum(HttpSession session,AcStbUserVotenum acvote){
		Map<String,Object> map=new HashMap<String,Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution =Integer.valueOf((String) session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION));//1.标清 2.高清
		acvote.setF_asuv_serverid(userid);
		acvote.setF_asuv_resolution(resolution);
		map = acIntegralService.insertUserVotenum(acvote);
		return map;
	}
	/**
	 * 订购，签到屯票
	 * @param session
	 * @param acvote f_asuv_activityid:活动编号；
	 * @return
	 */
	@RequestMapping("/insertUserVotenumByDay")
	@ResponseBody
	public Object insertUserVotenumByDay(HttpSession session,AcStbUserVotenum acvote,HttpServletRequest request,HttpServletResponse response){
		Map<String,Object> map=new HashMap<String,Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution =Integer.valueOf((String) session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION));//1.标清 2.高清
		acvote.setF_asuv_serverid(userid);
		acvote.setF_asuv_resolution(resolution);
		map = acIntegralService.insertUserVotenumByDay(acvote,request,response);
		return map;
	}
	/**
	 * 查询屯票总排行及个人排名
	 * @param session
	 * @param activityid
	 * @return
	 */
	@RequestMapping("/selectVoteTotalRownum")
	@ResponseBody
	public Object selectVoteTotalRownum(HttpSession session,String activityid,int start,int pageSize,String type,String voteid){
		Map<String,Object> map = new HashMap<String,Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		map = acIntegralService.selectVoteTotalRownum(userid,activityid,start,pageSize,type,voteid);
		return map;
	}

	/**
	 * @Description: 获取广场舞剩余天数
	 * @Param:
	 * @return: success result：几天
	 */
	@RequestMapping("/getGCWLastDay")
	@ResponseBody
	public Object getGCWLastDay(){
		return acIntegralService.getGCWLastDay();
	}
	
	/**
	 * 查询广场舞活动复赛获取每日囤票数
	 * @param f_asuv_activityid 活动id
	 * @param f_asuv_source  1有料签到，2产品开通，3赠票卡，4订购赠票，5每日签到送票，6抽奖的票
	 * @param f_asuv_serverid 用户id
	 * @param f_asuv_resolution 高标清  1标清  2高清     0未知   已从session中获取
	 * @param f_asuv_startTime 票数有效时间   当天有效  此接口内部已完成 开始与结束时间提取，不用再传此参数
	 * @param f_asuv_endTime   票数有效结束时间
	 * @return day_count:每日基础票数  order_count:订购获得票数  ylqd_count:有料签到获得票数  cpkt_count:产品开通获得票数  zpk_count:赠票卡获得票数 lott_count:抽奖获得票数
	 */
	@RequestMapping(value="/selectGCWRepechargeDayVotes")
	@ResponseBody
	public Object selectGCWRepechargeDayVotes(AcStbUserVotenum acvote,HttpServletRequest request) {
		return acIntegralService.selectGCWRepechargeDayVotes(acvote,request);
	}
	/**
     *查询当前时间是否到广场舞复赛的囤票时间
     * @Param session
     * @Return result：false 没到囤票时间 result：true 到囤票时间
     **/
    @RequestMapping(value="/selectGCWRepechargeHoard")
    @ResponseBody
	public Object getHoardFlag(){
	    Map<String,Object> map=new HashMap<String, Object>();
        int gd_service_ac_gcw_openTime = Integer.valueOf(SystemConfigUtils.getSysConfig(SessionKey.SESSION_SYSTEM_CONFIG.gd_service_ac_gcw_openTime.getKey()));
        int gd_service_ac_gcw_closeTime = Integer.valueOf(SystemConfigUtils.getSysConfig(SessionKey.SESSION_SYSTEM_CONFIG.gd_service_ac_gcw_closeTime.getKey()));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        boolean flag = false;
        try {
            int time = Integer.valueOf(sdf.format(new Date()));
            if (time >= gd_service_ac_gcw_openTime && time <= gd_service_ac_gcw_closeTime) {
                flag = true;
            }
        }catch (Exception e){
            LOG.error("时间错误:"+e);

        }
        map.put("result",flag);
        return map;
    }
	/**
	 *查询当前时间是否到广场舞巅峰决赛的时间间隔
	 * @Param session
	 * @Return result： orderFlag：true/false是否订购少儿，影视，戏迷
	 * leftnote：剩余要投的票数
	 * leftTime：距离下一个10分钟还差多少秒
	 **/
	@RequestMapping(value="/selectSummitFinals")
	@ResponseBody
	public Object getSummitFinals(HttpSession session,String f_avu_activityid,HttpServletRequest request,HttpServletResponse response){
		Map<String,Object> map=new HashMap<String, Object>();
		Date newDate=new Date();
		//查询已投票数
		Map<String,Object> usedmap = new HashMap<String,Object>();
		int used_count=0;
		Boolean orderFlag=false;//默认是没有订购
		Map<String,Object> newmap = new HashMap<String,Object>();
		ActivityVoteUserVo acv=new ActivityVoteUserVo();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		acv.setF_avu_serverid(userid);
		acv.setF_avu_memo("广场舞巅峰对决票数");
		acv.setF_avu_activityid(f_avu_activityid);
		usedmap= acIntegralService.selectAcLikeVotenum(acv);//获取到已投票数
		used_count = Integer.parseInt(usedmap.get("used").toString());
		int round=600;//取出距离下一个10分钟还差多少秒
		int left=0;
		Boolean endFlag=false;// 默认没有到投票结束时间
		int endTime=0;//距离投票结束还剩多少秒
		Integer readTimeOut = 3000;
		Integer connectTimeout = 3000;
		try{//开始时间
			//判断用户是否订购
			Map<String,Object> orderMap=epgComService.getOrderType(userid,request,response);
			AuthenticatedService authenticatedService = new AuthenticatedService(request,response);
			String Result= authenticatedService.getAuthenticatedResult(userid, "00000001000000110000000000000406",readTimeOut,connectTimeout);
			if("0".equals(Result)){
				orderFlag=true;
			}else{
				if("0".equals(orderMap.get("result"))){//订购标识
					if("0".equals(orderMap.get("mtv_month"))||"0".equals(orderMap.get("mtv_ThirdLine"))){
						orderFlag=true;
					}else{
						if("0".equals(orderMap.get("xm_month"))||"0".equals(orderMap.get("xm_ThirdLine"))){
							orderFlag=true;
						}
					}
				}
			}

			Date startDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(SystemConfigUtils.getSysConfig(SessionKey.SESSION_SYSTEM_CONFIG.gcw_addVote_startTime.getKey()));
            Date endDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(SystemConfigUtils.getSysConfig(SessionKey.SESSION_SYSTEM_CONFIG.gcw_addVote_endTime.getKey()));
			Long startAmount=newDate.getTime()-startDate.getTime();//总的间隔毫秒数
            Long endAmount=endDate.getTime()-newDate.getTime();//结束时间间隔
			endTime=(int)Math.floor(endAmount/1000);
			//剩余票数有多少个10分钟
			if(orderFlag){
				left=10*2*((int)Math.floor(startAmount/600000))-used_count;
			}else{
				left=10*(int)Math.floor(startAmount/600000)-used_count;
			}
			if(left<0){
				left=0;
			}
			//剩余多少秒距离下一个10分钟时间
			if(startAmount<60*10*1000){//小于10分钟
				round=(int)Math.floor(((1000*10*60)-startAmount)/1000);
			}else if(startAmount>60*10*1000){//大于10分钟
				round=(int)Math.floor((600000-(startAmount%(1000*10*60)))/1000);
			}else{
				round=0;
			}
			if(endAmount>0){
				endFlag=false;
            }else{
				endFlag=true;//投票结束
            }
		}catch (Exception e){
			LOG.error("时间错误:"+e);
		}
		map.put("leftnote",left);//剩余票数
		map.put("leftTime",round);//距离下一个10分钟还差多少秒
		map.put("orderFlag",orderFlag);
		map.put("endFlag",endFlag);//投票没有结束
		map.put("endTime",endTime);//距离投票结束还剩多少秒
 		return map;
	}
	/**
	 *通过服务ids鉴权 2020 鼠年有福活动
	 * @Param session
	 * @Return Result： 0是订购
	 **/
	@RequestMapping(value="/authenticatedServices")
	@ResponseBody
	public Object authenticatedServices(HttpSession session,HttpServletRequest request,HttpServletResponse response){
		Map<String,Object> map=new HashMap<String, Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		String Result = "504";
		Integer readTimeOut = 3000;
		Integer connectTimeout = 3000;
		String [] serverids={"00000001000000110000000000000406","00000001000000110000000000000443","00000001000000110000000000000430","00000001000000110000000000000428",
		            	        "00000001000000110000000000000497","00000001000000110000000000000495","00000001000000110000000000000505","00000001000000110000000000000503",
		            	        "00000001000000110000000000000499","00000001000000110000000000000501","00000001000000110000000000000507","00000001000000110000000000000523",
		            	        "00000001000000110000000000000458","00000001000000110000000000000410",
		            	        "00000001000000110000000000000441"};
		try{
			AuthenticatedService authenticatedService = new AuthenticatedService(request,response);
			for(int i=0;i<serverids.length;i++){
				String result= authenticatedService.getAuthenticatedResult(userid, serverids[i],readTimeOut,connectTimeout);
				if("0".equals(result)){
					Result="0";
					break;
				}
			}
		}catch (Exception e){
			LOG.error("鉴权错误:"+e);
		}
		map.put("Result",Result);
 		return map;
	}
	/**
	 * status=0时记录开始播放时间，status=1时计算播放总时长并入库
	 * @Param AcWinningVo f_awl_prizeid：关卡id,f_awl_prizename:内容名称，f_awl_activityid：活动id
	 * @Param limitTime 播放时间
	 * @Param status 0:播放开始 ，1：播放结束
	 * @Return updateTime:播放开始时间，playTime：播放总时长，status 0:播放开始 ，1：播放结束
	 **/
	@RequestMapping(value="/updatePlayTime")
	@ResponseBody
	public Object updatePlayTime(HttpSession session,AcWinningVo awv,int limitTime,String status){
		Map<String,Object> map=new HashMap<String, Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution= Integer.valueOf((String) session.getAttribute("SESSION_EPG_RESOLUTION"));
		awv.setF_ui_resolution(resolution);
		awv.setF_awl_serverid(userid);
		map = acIntegralService.updatePlayTime(awv, limitTime, status);
		return map;
	}
	/**
	 * 插入用户喂食流水记录表
	 * @param session
	 * @param f_asuv_serverid,用户id;f_asuv_activityid:活动编号；
	 *        f_asuv_votenum：票数；f_asuv_source：票数来源；f_asuv_memo：备注，建议携带
	 * @return result:0成功，-1系统错误，-2已投喂
	 */
	@RequestMapping("/insertFeedNum")
	@ResponseBody
	public Object insertFeedNum(HttpSession session,AcStbUserVotenum acvote,int allCount){
		Map<String,Object> map=new HashMap<String,Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution =Integer.valueOf((String) session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION));//1.标清 2.高清
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String time = sdf.format(new Date());
		acvote.setF_asuv_startTime(time+" 00:00:00");
		acvote.setF_asuv_endTime(time+" 23:59:59");
		List<AcStbUserVotenum> list= acIntegralService.selectAcStbUserVotenumList( acvote);
		if(list.size()>=allCount && allCount>0){
			map.put("result", -2);
			return map;
		}
		acvote.setF_asuv_serverid(userid);
		acvote.setF_asuv_resolution(resolution);
		map = acIntegralService.insertFeedNum(acvote);
		Map<String,Object> randMap = new HashMap<String,Object>();
		randMap = acIntegralService.selectVoteTotalRownum(userid,acvote.getF_asuv_activityid(),0,1,"2","");
		map.put("myList", randMap.get("myList"));
		return map;
	}
	/**
	 * 交警签到 并返回签到结果
	 * @param session
	 * @param f_asuv_serverid,用户id;f_asuv_activityid:活动编号；sync:1测试使用,同步返回的状态码，
	 *        f_asuv_votenum：票数；f_asuv_source：票数来源；f_asuv_memo：备注，建议携带,fiveNum 连续签到五天额外积分
	 *        {
	 *        "activityCode": "category_code_2001",
				"extraCode": "item_code_200101",
				"remark": "交警专区签到"
				}
	 * @return signFlag:1当天第一次成功签到，用于显示弹框,signTodayFlag:1当天签到成功状态，signDayNum:连续签到天数,signExtraFlag：1当天已获得额外积分
	 */
	@RequestMapping("/policeAreaSignIn")
	@ResponseBody
	public Object policeAreaSignIn(HttpSession session,AcStbUserVotenum acvote,int fiveNum,String activityCode,String extraCode,String remark,String sync){
		Map<String,Object> returnMap=new HashMap<String,Object>();
		Map<String,Object> map=new HashMap<String,Object>();
		Map<String,Object> fiveMap=new HashMap<String,Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		LOG.debug("交警测试签到开始userid："+userid+",activityCode:"+activityCode+",extraCode:"+extraCode+",remark:"+remark+",sync:"+sync);
		int resolution =Integer.valueOf((String) session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION));//1.标清 2.高清
		acvote.setF_asuv_serverid(userid);
		acvote.setF_asuv_resolution(resolution);
		Long todayTimes=RedisService.getTodayDayLastMis(0);
		Long afterTimes=RedisService.getTodayDayLastMis(1);
		String statusCode="200";
		statusCode=(sync!=null&&"1".equals(sync))?"500":statusCode;
		String signTodayFlag=RedisUtils.getString("POICESIGNIN_TODAYFLAG_", userid);//当天是否签到
		String signTodayFlagSync=RedisUtils.getString("POICESIGNIN_TODAYFLAG_SYNC_", userid);//当天是否同步成功
		String signExtraFlag=RedisUtils.getString("POICESIGNIN_EXTRAFLAG_", userid);//当天是否已累计签到
		String signExtraFlagSync=RedisUtils.getString("POICESIGNIN_EXTRAFLAG_SYNC_", userid);//当天累计签到是否同步成功
		String signDayNum=RedisUtils.getString("POICESIGNIN_NUM_", userid);//连续签到天数
		String signFlag="0";
		LOG.debug("交警签到开始userid："+userid+",signTodayFlag:"+signTodayFlag+",signTodayFlagSync:"+signTodayFlagSync+",signExtraFlag:"+signExtraFlag+",signExtraFlagSync:"+signExtraFlagSync+",signDayNum:"+signDayNum);
		if(signTodayFlag==null){
			if(signTodayFlagSync!=null){//同步成功，但入库失败，可再入库，不再同步
				map = acIntegralService.insertFeedNum(acvote);
			}else{//未同步，未入库，=》进行同步和入库
				Map<String,Object> syncMap = iptvServiceBean.pointsProduce(userid,activityCode,extraCode,remark,acvote.getF_asuv_votenum(),acvote.getF_asuv_activityid());
				LOG.debug("当天签到积分同步结果，userid："+userid+",syncMap:"+syncMap.toString());
				if(statusCode.equals(syncMap.get("status").toString())){//同步成功
					RedisUtils.setStringUnix("POICESIGNIN_TODAYFLAG_SYNC_", userid,"1",todayTimes);
					map = acIntegralService.insertFeedNum(acvote);
				}
			}
			LOG.debug("当天签到入库成功insertFeedNum，userid："+userid+",map:"+map.toString());
			if(map.get("result")!=null && "0".equals(map.get("result").toString())){
				signFlag="1";
				RedisUtils.setStringUnix("POICESIGNIN_TODAYFLAG_", userid,"1",todayTimes);
				LOG.debug("当天签到入库成功，userid："+userid+",todayTimes:"+todayTimes);
			}
		}
		if(signExtraFlag==null){//当天是否已累计签到
			signDayNum=signDayNum==null?"1":String.valueOf(Integer.parseInt(signDayNum)+1);
			if("5".equals(signDayNum)){
				if(signExtraFlagSync!=null){//同步成功，但入库失败，可再入库，不再同步
					acvote.setF_asuv_votenum(fiveNum);
					acvote.setF_asuv_memo("连续签到5天获得积分："+fiveNum);
					fiveMap =acIntegralService.insertFeedNum(acvote);
				}else{
					Map<String,Object> syncMap = iptvServiceBean.pointsProduce(userid,activityCode,extraCode,remark,fiveNum,acvote.getF_asuv_activityid());
					LOG.debug("连续5天签到积分同步结果，userid："+userid+",syncMap:"+syncMap.toString());
					if(statusCode.equals(syncMap.get("status").toString())){//同步成功
						RedisUtils.setStringUnix("POICESIGNIN_EXTRAFLAG_SYNC_", userid,"1",todayTimes);
						acvote.setF_asuv_votenum(fiveNum);
						acvote.setF_asuv_memo("连续签到5天获得积分："+fiveNum);
						fiveMap =acIntegralService.insertFeedNum(acvote);
					}
				}
				LOG.debug("连续签到5天入库成功insertFeedNum，userid："+userid+",map:"+map.toString());
				if(fiveMap.get("result")!=null && "0".equals(fiveMap.get("result").toString())){
					RedisUtils.setStringUnix("POICESIGNIN_EXTRAFLAG_", userid,"1",todayTimes);
					RedisUtils.setStringUnix("POICESIGNIN_NUM_", userid,signDayNum,todayTimes);//第二天自动失效
				}
			}else{
				RedisUtils.setStringUnix("POICESIGNIN_NUM_", userid,signDayNum,afterTimes);//第二天不签到 自动失效
				RedisUtils.setStringUnix("POICESIGNIN_EXTRAFLAG_", userid,"1",todayTimes);//当天有效
			}
		}
		if("1".equals(signFlag)){
			signTodayFlag=signFlag;
		}
		returnMap.put("signDayNum", signDayNum);
		returnMap.put("signTodayFlag", signTodayFlag);
		returnMap.put("signFlag", signFlag);
		returnMap.put("signTodayMap", map);
		returnMap.put("signExtraMap", fiveMap);
		LOG.debug("交警签到结束userid："+userid+",returnMap:"+returnMap.toString());
		return returnMap;
	}
	/**交警专区观看视频获得积分
	 * status=0时记录开始播放时间，status=1时计算播放总时长
	 * @Param AcStbUserVotenum f_asuv_source：积分来源,f_asuv_memo:观看的内容id，f_asuv_activityid：活动id，f_asuv_votenum 播放获得的积分
	 * @Param limitTime 播放时间,limitPlayTimes 每天播放获得积分最大次数,sync:1测试使用,同步返回的状态码，
	 * @Param status 0:播放开始 ，1：播放结束
	 * {
	 *        "activityCode": "category_code_2001",
				"extraCode": "item_code_200101",
				"remark": "交警专区观看视频"
				}
	 * @Return updateTime:播放开始时间，playTime：播放总时长，status 0:播放开始 ，1：播放结束
	 **/
	@RequestMapping(value="/policeAreaPlayTime")
	@ResponseBody
	public Object policeAreaPlayTime(HttpSession session,AcStbUserVotenum acvote,int limitTime,int limitPlayTimes,String status,String activityCode,String extraCode,String remark,String sync){
		Map<String,Object> map=new HashMap<String, Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution= Integer.valueOf((String) session.getAttribute("SESSION_EPG_RESOLUTION"));
		acvote.setF_asuv_resolution(resolution);
		acvote.setF_asuv_serverid(userid);
		map = acIntegralService.policePlayTime(acvote,limitTime,limitPlayTimes,status,activityCode,extraCode,remark,sync);
		return map;
	}
	/**
	 * 插入问卷流水记录表
	 * @param session
	 * @param f_asuv_serverid,用户id;f_asuv_activityid:活动编号；
	 *        f_asuv_votenum：1；f_asuv_source：来源；f_asuv_memo：备注，问卷答案
	 * @return result:-1系统错误
	 */
	@RequestMapping("/insertQuestionnaire")
	@ResponseBody
	public Object insertQuestionnaire(HttpSession session,AcStbUserVotenum acvote){
		Map<String,Object> map=new HashMap<String,Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution =Integer.valueOf((String) session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION));//1.标清 2.高清
		acvote.setF_asuv_serverid(userid);
		acvote.setF_asuv_resolution(resolution);
		map = acIntegralService.insertQuestionnaire(acvote);
		return map;
	}
	/**
	 * 查询问卷流水记录表
	 * @param session
	 * @param f_asuv_serverid,用户id;f_asuv_activityid:活动编号；
	 *        f_asuv_source：来源
	 * @return List<AcStbUserVotenum>
	 */
	@RequestMapping("/selectQuestionnaire")
	@ResponseBody
	public Object selectQuestionnaire(HttpSession session,AcStbUserVotenum acvote){
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		acvote.setF_asuv_serverid(userid);
		List<AcStbUserVotenum> list= acIntegralService.selectQuestionnaire( acvote);
		return list;
	}
	/**
	 * 查询
	 * @param session
	 * @param f_csvt_activityid,活动编号;f_csvt_contentid:目标id；
	 * @return List<CmSvcVoteTotalVo>
	 */
	@RequestMapping("/selectCmSvcVoteTotal")
	@ResponseBody
	public Object selectCmSvcVoteTotal(HttpSession session,CmSvcVoteTotalVo csvt){
		List<CmSvcVoteTotalVo> cs = acIntegralService.selectCmSvcVoteTotal(csvt);
		return cs;
	}
	/**
	 * 查询问卷流水记录表列表
	 * @param session
	 * @param f_asuv_activityid:活动编号；
	 *        f_asuv_source：来源
	 * @return List<AcStbUserVotenum>
	 */
	@RequestMapping("/selectQuestionnaireList")
	@ResponseBody
	public Object selectQuestionnaireList(HttpSession session,AcStbUserVotenum acvote){
		List<AcStbUserVotenum> list= acIntegralService.selectQuestionnaire( acvote);
		return list;
	}
	
	/**
	 * status=0时记录开始播放时间，status=1时计算播放总时长并入库
	 * @Param status 0:播放开始 ，1：播放结束
	 * @Return updateTime:播放开始时间，playTime：播放总时长，status 0:播放开始 ，1：播放结束
	 **/
	@RequestMapping(value="/getPlayTime")
	@ResponseBody
	public Object getPlayTime(HttpSession session,AcWinningVo awv,String status){
		Map<String,Object> map=new HashMap<String, Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution= Integer.valueOf((String) session.getAttribute("SESSION_EPG_RESOLUTION"));
		awv.setF_ui_resolution(resolution);
		awv.setF_awl_serverid(userid);
		map = acIntegralService.getPlayTime(awv, status);
		return map;
	}
	
	/**
	 * 查询或者添加用户积分
	 * @param session
	 * @param f_asuv_serverid,用户id;f_asuv_activityid:活动编号；
	 *        f_asuv_votenum：票数；f_asuv_source：票数来源；f_asuv_memo：备注，建议携带
	 *        status 0:查询当天该用户已经获取多少积分 ，1：添加积分,2:查询积分排名,3:将积分转为奖品
	 *        allCount:查询积分排名前allCount名的用户
	 * @return result:0成功，-1系统错误，-2已投喂
	 */
	@RequestMapping("/selectOrInsertIntegralCount")
	@ResponseBody
	public Object selectOrInsertIntegralCount(HttpSession session,AcStbUserVotenum acvote,String status,int allCount){
		Map<String,Object> map=new HashMap<String,Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution =Integer.valueOf((String) session.getAttribute(SessionKey.SESSION_EPG_RESOLUTION));//1.标清 2.高清
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String time = sdf.format(new Date());
		acvote.setF_asuv_startTime(time+" 00:00:00");
		acvote.setF_asuv_endTime(time+" 23:59:59");
		acvote.setF_asuv_serverid(userid);
		acvote.setF_asuv_resolution(resolution);
		map = acIntegralService.selectOrInsertIntegralCount(acvote,status,allCount);
		return map;
	}
	
	/**
	 * 查询已投票数
	 * @param f_avu_activityid 活动id
	 * @param f_avu_serverid  投票人
	 * @param f_avu_contentid 目标id
	 * @param f_avu_startTime 投票开始时间
	 * @param f_avu_endTime   投票结束时间
	 * @return used：已投票数
	 */
	@RequestMapping(value="/convertVoteToWinningInformation")
	@ResponseBody
	public Object convertVoteToWinningInformation(HttpSession session,ActivityVoteUserVo acvote,int allCount) {
		Map<String,Object> map = new HashMap<String,Object>();
		map = acIntegralService.convertVoteToWinningInformation(acvote,allCount);
		return map;
	}
	
	/**
	 * 追踪王记录视频开始及结束时间
	 * @Param status 0:播放开始 ，1：播放结束
	 * @Return convertIntegral:多长时间转换成一积分，playTime：播放总时长，status 0:播放开始 ，1：播放结束
	 **/
	@RequestMapping(value="/getTrackingKingPlayTime")
	@ResponseBody
	public Object getTrackingKingPlayTime(HttpSession session,AcWinningVo awv,String status,String convertIntegral,String masterThreshold,String kingThreshold,String pointsLimit){
		Map<String,Object> map=new HashMap<String, Object>();
		String userid= (String) session.getAttribute(SessionKey.SESSION_SERVERID);
		int resolution= Integer.valueOf((String) session.getAttribute("SESSION_EPG_RESOLUTION"));
		awv.setF_ui_resolution(resolution);
		awv.setF_awl_serverid(userid);
		map = acIntegralService.getTrackingKingPlayTime(awv, status, convertIntegral,masterThreshold,kingThreshold,pointsLimit);
		return map;
	}
	
}
